<template>
	<view class="container">
		<!-- 专题内容 -->
		<view class="content">
			<!-- 专题图片 -->
			<image :src="'/img' + detail[0].img" class="topic-image" mode="aspectFill"></image>
			<!-- 专题标题和描述 -->
			<view class="topic-info">
				<text class="topic-title">{{ detail[0].name }}</text>
				<br>
				<text class="topic-description">{{ detail[0].description }}</text>
			</view>
			<!-- 总节数和学习人数 -->
			<view class="topic-meta">
				<view class="meta-item">
					<text class="meta-value">{{ 3 }}</text>
					<text class="meta-label">总节数</text>
				</view>
				<view class="meta-item">
					<u-icon name="users" size="24" color="#f0b90b"></u-icon>
					<text class="meta-learners">已有{{ detail[0].num }}人学习</text>
				</view>
			</view>
			<!-- 介绍 -->
			<view class="topic-content">
				<text class="content-header">简介:</text>
				<br>
				<text class="content-text">{{ detail[0].introduction }}</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue'
	import {
		studyid
	} from '../../common/api';
	// 定义一个 ref 变量
	const itemDetail = ref(null);
	// 专题详情信息
	const detail = ref([{
		img: ''
	}])

	// 获取到id 查询
	onMounted(() => {
		// 获取当前页面实例
		const pages = getCurrentPages();
		// 获取上一页id
		const currentPage = pages[pages.length - 1];

		// 获取页面参数
		if (currentPage && currentPage.options) {
			itemDetail.value = currentPage.options.id;

			const params = {
				plantId: itemDetail.value
			}
			console.log(params.plantId);
			// 详细数据
			studyid(params)
				.then(res => {
					console.log(res); // 在 `Promise` 完成后打印结果
					detail.value = res.data;
				})
		}
	});
</script>

<style scoped>
	.container {
		background-color: #f5f5f5;
		height: 100%;
	}

	/* 顶部返回与标题栏 */
	.header {
		display: flex;
		align-items: center;
		padding: 20rpx;
		background-color: #fff;
	}

	.back-button {
		flex: 0 0 auto;
	}

	.header-title {
		flex: 1;
		text-align: center;
		font-size: 34rpx;
		font-weight: bold;
		color: #333;
	}

	.more-button {
		flex: 0 0 auto;
	}

	/* 专题内容部分 */
	.content {
		padding: 20rpx;
	}

	/* 专题图片 */
	.topic-image {
		/* background-color: #aaaa7f; */
		width: 100%;
		height: 300rpx;
		border-radius: 10rpx;
		margin-bottom: 20rpx;
	}

	/* 专题标题和描述 */
	.topic-info {
		background-color: #fff;
		padding: 20rpx;
		border-radius: 10rpx;
		margin-bottom: 20rpx;
	}

	.topic-title {
		font-size: 32rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 10rpx;
	}

	.topic-description {
		font-size: 28rpx;
		color: #666;
		line-height: 36rpx;
	}

	/* 总节数和学习人数 */
	.topic-meta {
		display: flex;
		justify-content: space-around;
		align-items: center;
		background-color: #fff;
		padding: 20rpx;
		border-radius: 10rpx;
		margin-bottom: 20rpx;
	}

	.meta-item {
		display: flex;
		align-items: center;
		flex-direction: column;
	}

	.meta-value {
		font-size: 34rpx;
		font-weight: bold;
		color: #39b54a;
		margin-bottom: 5rpx;
	}

	.meta-label {
		font-size: 28rpx;
		color: #666;
	}

	.meta-learners {
		font-size: 28rpx;
		color: #999;
		margin-left: 5rpx;
	}

	/* 专题介绍内容 */
	.topic-content {
		background-color: #fff;
		padding: 20rpx;
		border-radius: 10rpx;
	}

	.content-header {
		font-size: 32rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 15rpx;
	}

	.content-text {
		font-size: 28rpx;
		color: #666;
		line-height: 40rpx;
	}
</style>